package com.sjh;

import java.util.Random;

/**
 * @author jack
 * @data 2020/8/22 11:12 上午
 */
public class ThreadLocalTest {
    private static Integer data = 0;

    private static ThreadLocal threadLocal = new ThreadLocal<Integer>();

    public static void main(String[] args) {

//        for (int i = 0; i < 5; i++) {
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    data = new Random().nextInt();
//                    System.out.println(Thread.currentThread().getName() + " has put data :" + data);
//                    System.out.println("outPut data:" + data);
//
//                }
//            }).start();
//        }

        for (int i = 0; i < 5; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    threadLocal.set(new Random().nextInt());
                    System.out.println(Thread.currentThread().getName() + " has put data :" + threadLocal.get());
                    System.out.println("outPut data:" + threadLocal.get());
                }
            }).start();
        }

    }

}
